import "./index.less"
import Setup from "@/components/setup"
import { useNavigate } from "react-router-dom"
import { asyncAction } from "@/redux/actions/account"
import { DispatchProp, useDispatch } from 'react-redux';
import { message } from "antd";
import {resovePath} from "@/redux/actions/index"

function Login() {
    const router = useNavigate()
    const dispatch = useDispatch()

    const setLogin = (e: userInfo, isRemenber: boolean, type: string) => {
        if (type == 'error') {
            message.error("验证码错误")
            return
        }

        dispatch(asyncAction(e)).then((res: string) => {
            if (res == "success") {
                if (isRemenber) {
                    window.localStorage.setItem("user", JSON.stringify(e))
                }
                dispatch(resovePath())
                message.success("登录成功")
                // window.location.href = "/home"
                router("/home")
            }
        })


    }

    return (
        <div className="login flex_a_j_c">
            <div className="login_name">
                <img src="/image/login.png" alt="" className="login_img" />  客户关系管理系统
            </div>
            <Setup setLogin={setLogin} />
        </div>
    )
}

export default Login